package com.ruoyi.web.controller.system;


import cn.hxzy.common.util.RandomId;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzy.authentication.service.TsEnterpriseCertificationService;
import com.hxzy.system.entity.TtSettlementBody;
import com.hxzy.system.service.TtSettlementBodyService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mingqian.Wu
 * @since 2023-06-24
 */
@RestController
@RequestMapping("/ttSettlementBody")
@DataSource(DataSourceType.SYSTEM)
public class TtSettlementBodyController {
    @Autowired
    private TsEnterpriseCertificationService tsEnterpriseCertificationService;
   @Autowired
   private TtSettlementBodyService ttSettlementBodyService;
   @Anonymous
   @GetMapping("/getSettlementList/{pageIndex}/{pageSize}")
   public AjaxResult getSettlementList(@PathVariable Integer pageIndex,@PathVariable Integer pageSize){
       PageHelper.startPage(pageIndex,pageSize);
       List<TtSettlementBody> settlementBodyList = ttSettlementBodyService.list();
       PageInfo pageInfo=new PageInfo(settlementBodyList);
       long total = pageInfo.getTotal();
       return AjaxResult.success(settlementBodyList).put("total",total);
   }
   @Anonymous
   @GetMapping("/searchQueryList/{name}/{pageIndex}/{pageSize}")
   public AjaxResult searchQueryList(@PathVariable String name,@PathVariable Integer pageIndex,@PathVariable Integer pageSize){
       PageHelper.startPage(pageIndex,pageSize);
        QueryWrapper<TtSettlementBody> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("name",name);
        List<TtSettlementBody> list = ttSettlementBodyService.list(queryWrapper);
        PageInfo pageInfo=new PageInfo(list);
       long total = pageInfo.getTotal();
       return AjaxResult.success(list).put("total",total);
   }
   @DeleteMapping("/deletById/{id}")
    @Anonymous
   public AjaxResult deleteById(@PathVariable String id){
       boolean b = ttSettlementBodyService.removeById(id);
       if (b){
           return AjaxResult.success("删除成功");
       }
       return AjaxResult.error("删除失败");

   }
    @PostMapping("/newSettlement")
    @Anonymous
    public AjaxResult newSettlement(@RequestBody TtSettlementBody ttSettlementBody){
        String businessId = RandomId.getBusinessId();
        ttSettlementBody.setId(businessId);
        boolean save = ttSettlementBodyService.save(ttSettlementBody);
        if (save){
            return AjaxResult.success("新建成功");
        }
        return AjaxResult.success("新建失败");

    }

}

